﻿using Nancy;
using Nancy.Conventions;
using Nancy.TinyIoc;
using System;
using System.Configuration.Abstractions;
using System.IO;

namespace Sustainalytics.ClientInterface.AngularHosting.Service
{
    public class Bootstrapper : DefaultNancyBootstrapper
    {
        protected override void ApplicationStartup(TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
        {            
        }

        protected override void ConfigureConventions(NancyConventions nancyConventions)
        {
            var sitePath = Path.GetFullPath(ConfigurationManager.Instance.AppSettings.AppSettingSilent<string>("SiteLocation", () => ""));

            Console.WriteLine("Site hosted at path " + sitePath);

            // static content
            nancyConventions.StaticContentsConventions.Clear();
            nancyConventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("", sitePath));
        }

        protected override IRootPathProvider RootPathProvider
        {
            get { return new CustomRootPathProvider(); }
        }

    }

    public class CustomRootPathProvider : IRootPathProvider
    {
        public string GetRootPath()
        {
            return Path.GetFullPath(ConfigurationManager.Instance.AppSettings.AppSettingSilent<string>("SiteLocation", () => ""));
        }
    }
}
